home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / network / ncsasock / syslog.c < prev    next >
Text File  |  1996-07-05  |  2KB  |  102 lines

  1. /*
  2.  * BSD-style socket emulation library for the Mac
  3.  * Original author: Tom Milligan
  4.  * Current author: Charlie Reiman - creiman@ncsa.uiuc.edu
  5.  *
  6.  * This source file is placed in the public domian.
  7.  * Any resemblance to NCSA Telnet, living or dead, is purely coincidental.
  8.  *
  9.  *      National Center for Supercomputing Applications
  10.  *      152 Computing Applications Building
  11.  *      605 E. Springfield Ave.
  12.  *      Champaign, IL  61820
  13.  */
  14.  
  15. /*
  16.  * syslog, openlog, closelog - hacked from Unix - use dprintf
  17.  * perror - hacked from Unix - uses dprintf
  18.  * Modified to use StdArg by Charlie Reiman.
  19.  * Wednesday, August 8, 1990 2:55:43 PM
  20.  */
  21.  
  22. #include <syslog.h>
  23. #include <StdArg.h>
  24.  
  25. #ifndef _ERRNO
  26. extern int errno;
  27. #endif
  28. extern int sys_nerr;
  29. extern char *sys_errlist[];
  30.  
  31. /*
  32.  * a version of dprintf was here, but it was also defined in
  33.  * dprintf.c. I've removed this one.
  34.  * Charlie Reiman
  35.  * Wednesday, August 8, 1990 2:53:49 PM
  36.  */
  37.  
  38. void dprintf(char *fmt,...);
  39.  
  40. #define MAXLINE 1000
  41.  
  42. static int LogMask = LOG_DEBUG;
  43. static char LogTag[100] = "";
  44.  
  45. openlog(char *ident, int logstat)
  46. {
  47.     if (logstat >= LOG_ALERT && logstat <= LOG_DEBUG)
  48.         LogMask = logstat;
  49.         
  50.     if (ident)
  51.         strcpy(LogTag,ident);
  52.     return 0;
  53. }
  54.  
  55. closelog()
  56. {
  57.     return 0;
  58. }
  59.  
  60. syslog(int pri,char *fmt,...)
  61. {
  62.     register char *b, *f = fmt, c;
  63.     char buf[MAXLINE+50];
  64.     char oline[MAXLINE];
  65.     va_list nextArg;
  66.     
  67.     va_start(nextArg,fmt);
  68.     
  69.     if (pri > LogMask)
  70.         return 0;
  71.  
  72.     b = buf;
  73.     while ((c = *f++) != '\0' && b < buf + MAXLINE) 
  74.     {
  75.         if (c != '%') 
  76.         {
  77.             *b++ = c;
  78.             continue;
  79.         }
  80.         c = *f++;
  81.         if (c != 'm') 
  82.         {
  83.             *b++ = '%', *b++ = c;
  84.             continue;
  85.         }
  86.         if ((unsigned)errno > sys_nerr)
  87.             sprintf(b, "error %d", errno);
  88.         else
  89.             sprintf(b, "%s", sys_errlist[errno]);
  90.         b += strlen(b);
  91.     }
  92.     if (b[-1] != '\n')
  93.         *b++ = '\n';
  94.     *b = '\0';
  95.         
  96.     vsprintf(oline, buf, nextArg);
  97.  
  98.     dprintf("%s: %s\n", LogTag,oline);
  99.     return 0;
  100. }
  101.  
  102.